package com.jwork.progress.config;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OrderMQConfig {
    @Value("${rocketMq.nameServer}")
    private String nameServer;

    @Bean
    public DefaultMQProducer orderProducer() {
        try {
            DefaultMQProducer producer = new DefaultMQProducer("order_producer_group");
            producer.setNamesrvAddr(nameServer);
            producer.start();
            return producer;
        } catch (MQClientException e) {
            System.out.println("连接异常：" + e.getMessage());
            throw new RuntimeException(e);
        }
    }
}
